package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getAllNursingLevel() {
        return nursingLevelMapper.getAllNursingLevel();
    }

    @Override
    public void insertNursingLevel(NursingLevelVo nursingLevel) {
        NursingLevel level = BeanUtil.toBean(nursingLevel, NursingLevel.class);
        nursingLevelMapper.insertNursingLevel(level);
    }

    @Override
    public PageResponse<NursingLevelVo> listByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.listByPage(pageNum, pageSize, name, status);
        return PageResponse.of(page, NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo getById(Long id) {
        return nursingLevelMapper.getById(id);
    }

    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevel) {
        NursingLevel level = BeanUtil.toBean(nursingLevel, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(level);
    }

    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingLevelMapper.updateStatus(id, status);
    }
}
